package main;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;



import eg.com.itiga.business.base.BaseService;
import eg.com.itiga.business.company.CompanyService;
import eg.com.itiga.business.factory.BusinessFactory;
import eg.com.itiga.business.itian.ItianService;
import eg.com.itiga.business.role.RoleService;
import eg.com.itiga.domain.Company;
import eg.com.itiga.domain.ContactDetails;
import eg.com.itiga.domain.Itian;
import eg.com.itiga.domain.RegCompany;
import eg.com.itiga.domain.User;
import eg.com.itiga.domain.Role;

public class CompanyMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
			
		try
		{
			//calling the companyService in order to add the new registered company
			
			BaseService baseService = BusinessFactory.createBaseService();
		       
			//calling the roleService to get the "company" role
			RoleService roleService = BusinessFactory.createRoleService();
			Role companyRole = roleService.getRoleByName("Company");
			
			
			//creating a new user for the registered company with username/password abx/abx 
			//and setting it's Role to companyRole
			
			User abxUser = new User(companyRole,"aka","aka");
			
			RegCompany regCompany = new RegCompany();
			regCompany.setUser(abxUser);
			regCompany.setCName("aka");
			regCompany.setCIsRegistered(true);
			//regCompany.setRegExpDate(new Date());
			regCompany.setRegWesite("www.aka.com");
			Set<ContactDetails> contactDetails = new HashSet<ContactDetails>();
			
			ContactDetails c = new ContactDetails();
			c.setConAddress("x street");
			c.setConBranch("Cairo");
			c.setConEmail("akaa@aka.com");
			c.setConPhone("1234567");
			c.setRegCompany(regCompany);
			contactDetails.add(c);
			//contactDetails.add();
			regCompany.setContactDetailses(contactDetails); 
			
			baseService.add(regCompany);
			
			System.out.println("A new Company is Added");
			
			
			RegCompany resc = (RegCompany) baseService.find(RegCompany.class, 1);
			
			System.out.println("Company name: "+resc.getCName());
			System.out.println("Company website: "+resc.getRegWesite());
			System.out.println("Company Expiration Date: "+resc.getRegExpDate());
			
			Set<ContactDetails> res = resc.getContactDetailses();
			
			for(ContactDetails tmp : res)
			{
				System.out.println("Address: "+tmp.getConAddress());
				System.out.println("branch: "+tmp.getConBranch());
				System.out.println("E-Mail: "+tmp.getConEmail());	
			}
			
					
			
			
			
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.out.println("error adding company");
			
		}
	}

}
			
			
			
			
			
			
			
			
		
		
			
			
		
	
		
		


